<?php
namespace App\Service\Admin;

use Illuminate\Support\Facades\DB;

class UserService extends BaseService
{
    //用户


    //列表
    public function getIndex($pages)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $db = $this->dbConn($this->dbUser);
        $total = $db->count();
        $res = $db->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $comOne = (array) $this->dbConn($this->dbCompany)
                ->where('id', $v['cid'])
                ->first();
            $com_name = empty($comOne) ? '-' : $comOne['cname'];
            $arys[] = [
                'id' => $v['id'],
                'uname' => $v['uname'],
                'cname' => $com_name,
                'addtime' => $v['addtime'],
                'uptime' => $v['uptime'],
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }


    //设计公司列表
    public function getDesignComIndex($pages)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $db = $this->dbConn($this->dbCompany)->where('type', 3);
        $total = $db->count();
        $res = $db->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $arys[] = [
                'id' => $v['id'],
                'cname' => $v['cname'],
                'clogo' => file_exists($v['logo']) ? '/'.$v['logo'] : '',
                'address' => $v['address'] ? $v['address'] : '-',
                'uptime' => $v['uptime'] ? $v['uptime'] : '-',
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }
}